---@class UIChapterBox : UIBase
UIChapterBox = UIBase.New(PanelNames.UIChapterBox)
local t = UIChapterBox

function t.Init(func)
    UIBase.Init(t, func)
end

function t:OnCreate()
    self.Btn_BgClose = self:GetChild("Btn_BgClose")
    ---@type FairyGUI.GLoader3D
    self.Effect_ChapterBox = self:GetChild("Effect_ChapterBox")
    self:RegisterOnClick(self.Btn_BgClose,self.ClickClose)
    --self:RegisterEvent(Config.EventType.ChapterTaskRewardGetDone,self.RewardGetDoneMsg)
end

function t:OnEnable()
    self.isClickable = false
    self.Effect_ChapterBox.visible = false
    utimer.remove(self.timerId)
    self.timerId = utimer.delayCall(self.DelayCall,500,self)
end
function t:OnDisable()
    utimer.remove(self.timerId)
end
function t:OnDestroy()
end
function t:DelayCall()
    if self == nil then return end
    self.Effect_ChapterBox.visible = true
    AudioManager.Play(AudioManager.Play_UI_Award_Box_Drop)
    --掉下
    local time = Util.PlayAction(self.Effect_ChapterBox.wrapTarget,"idle3")
    self.timerId = utimer.delayCall(self.Loop,(time/Time.timeScale)*1000-200,self)
end
function t:Loop()
    self.isClickable = true
    --循环
    --Util.PlayAction(self.Effect_ChapterBox.wrapTarget,"idle4")
    self:ClickClose()
end
--[[function t:EnableClick()
    self.isClickable = true
end]]
function t:ClickClose()
    if not self.isClickable then
        return
    end
    self.isClickable = false
    --self.timerId2 = utimer.delayCall(self.EnableClick,5000,self)
    --打开
    AudioManager.Play(AudioManager.Play_UI_Award_Box_Open)
    utimer.remove(self.timerId2)
    local time = Util.PlayAction(self.Effect_ChapterBox.wrapTarget,"idle5")
    self.timerId = utimer.delayCall(self.Finished,(time/Time.timeScale)*1000,self)
    utimer.delayCall(self.Callback,(800/Time.timeScale),self)

end
function t:Finished()
    closeUI(self._panelName)
    self.timerId2 = nil
    self.timerId = nil
end
function t:Callback()
    if self.backFunc ~= nil then
        self.backFunc()
    end
    self.backFunc = nil
end
--[[function t:RewardGetDoneMsg()

end]]
return t